package com.swallow.weixin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swallow.weixin.entity.model.User;
import com.swallow.weixin.entity.vo.ResultVO;
import com.swallow.weixin.utils.ResponseBuilderUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.swallow.weixin.service.IUserService;
import com.swallow.weixin.base.service.IBaseService;
import com.swallow.weixin.base.controller.AbstractBaseController;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author swallow
 * @since 2019-01-09
 */
@RestController
@RequestMapping("/user")
public class UserController extends AbstractBaseController{
    @Autowired
    private IUserService userService;

    @Override
    protected IBaseService getBaseService() {
        return userService;
    }
    @RequestMapping(value = "/list")
    public ResultVO listVO(User user, @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
                           HttpServletRequest request, HttpServletResponse response){
        Page<User> userPage = new Page<>(pageNo, pageSize);
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>(user);
        IPage<User> page = userService.page(userPage,userQueryWrapper);
        return ResponseBuilderUtil.buildSuccessJson(page);
    }

}
